home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11732 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: galaxy.ucr.edu!not-for-mail
  2. From: thp@cs.ucr.edu (Tom Payne)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Will JAVA kill C++?
  5. Date: 15 Mar 1996 23:04:10 GMT
  6. Organization: University of California, Riverside
  7. Message-ID: <4ict1a$skr@galaxy.ucr.edu>
  8. References: <313E44EA.14D110C0@netcom.com> <4hp18v$3di@frodo.smartlink.net>
  9. NNTP-Posting-Host: corvette.ucr.edu
  10. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  11.  
  12. Matt Austern (austern@isolde.mti.sgi.com) wrote:
  13. : In article <4hqkfk$20j@galaxy.ucr.edu> thp@cs.ucr.edu (Tom Payne) writes:
  14. : > : In C++, or Fortran, or Eiffel, you can have an array of complex
  15. : > : numbers.  In Java, though, you can't: you can have something that
  16. : > : looks like an array of complex numbers, but internally it's really an
  17. : > : array of pointers to complex numbers.  You have to pay a space penalty
  18. : > : to store those pointers, and a time penalty to do the dereferencing on
  19. : > : every element, and the optimizer will have to generate code on
  20. : > : assumption that two array elements might point to the same object.
  21. : > 
  22. : > Are these references resettable?  If not, how can they be made to
  23. : > collide like that?  In fact, if they are not resettable, is there
  24. : > any reason that the extra level of indirection couldn't be 
  25. : > optimized away?
  26. : public class complex
  27. : {
  28. :     public complex(double re, double im)
  29. :     {
  30. :     Re = re;
  31. :     Im = im;
  32. :     }
  33. :     public double Re;
  34. :     public double Im;
  35. : }
  36. : class F
  37. : {
  38. :     static public void f()
  39. :     {
  40. :        complex[] A = new complex[3];
  41. :        A[0] = new complex(1, 1);
  42. :        A[1] = new complex(0, 1);
  43. :        A[2] = A[0];    // A[0] and A[2] point to the same object.
  44.  
  45. Ah so!!
  46.  
  47. : I don't see that Java solves any aliasing problems.  It does have
  48. : pointers, and the fact of pointer semantics is very clearly visible to
  49. : the user in many different ways.  I don't see how you could optimize
  50. : away anything so fundamental and pervasive; if you're able to write an
  51. : optimizer that can perform heroics like that, then dealing with the
  52. : aliasing problems in C and C++ would be trivial.
  53.  
  54. Yup!  In the presence of such reference-induced aliasing, the
  55. indirection cannot be ignored, making life much more difficult for the
  56. optimizer.  (Index-induced aliasing already makes it difficult
  57. enough.)
  58.  
  59. Tom Payne (thp@cs.ucr.edu)
  60.  
  61.